package com.ruoyi.course.service.impl;

import java.util.ArrayList;
import java.util.List;

import com.ruoyi.course.domain.CoursePart;
import com.ruoyi.course.dto.bo.CommonRespBO;
import com.ruoyi.course.mapper.CoursePartMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.course.mapper.CourseBanMapper;
import com.ruoyi.course.domain.CourseBan;
import com.ruoyi.course.service.ICourseBanService;

/**
 * 班级Service业务层处理
 *
 * @author mac
 * @date 2023-03-11
 */
@Service public class CourseBanServiceImpl implements ICourseBanService {
    @Autowired private CourseBanMapper courseBanMapper;

    @Autowired private CoursePartMapper coursePartMapper;

    /**
     * 查询班级
     *
     * @param id 班级主键
     * @return 班级
     */
    @Override public CourseBan selectCourseBanById(Long id) {
        return courseBanMapper.selectCourseBanById(id);
    }

    /**
     * 查询班级列表
     *
     * @param courseBan 班级
     * @return 班级
     */
    @Override public List<CourseBan> selectCourseBanList(CourseBan courseBan) {
        return courseBanMapper.selectCourseBanList(courseBan);
    }

    /**
     * 新增班级
     *
     * @param courseBan 班级
     * @return 结果
     */
    @Override public int insertCourseBan(CourseBan courseBan) {
        return courseBanMapper.insertCourseBan(courseBan);
    }

    /**
     * 修改班级
     *
     * @param courseBan 班级
     * @return 结果
     */
    @Override public int updateCourseBan(CourseBan courseBan) {
        return courseBanMapper.updateCourseBan(courseBan);
    }

    /**
     * 批量删除班级
     *
     * @param ids 需要删除的班级主键
     * @return 结果
     */
    @Override public int deleteCourseBanByIds(Long[] ids) {
        return courseBanMapper.deleteCourseBanByIds(ids);
    }

    /**
     * 删除班级信息
     *
     * @param id 班级主键
     * @return 结果
     */
    @Override public int deleteCourseBanById(Long id) {
        return courseBanMapper.deleteCourseBanById(id);
    }

    @Override public List<CommonRespBO> getPartNames() {
        List<CoursePart> courseParts = coursePartMapper.selectCoursePartList(null);
        List<CommonRespBO> bos = new ArrayList<>();
        courseParts.forEach(t -> {
            CommonRespBO bo = new CommonRespBO();
            bo.setLabel(t.getPartName());
            bo.setValue(t.getId());
            bos.add(bo);
        });
        return bos;
    }
}
